<template>
	<view class="contain">
		<view class="head w-[100%]"><image class="w-[100%]" src="https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/bg/buybg.jpg" mode="widthFix"></image></view>
		<view class="mt-9 flex justify-center"><text class="mid blod">身份证绑定</text></view>
		<view class="mt-5 flex justify-center flex-col m-auto w-[80%]">
			<view>
				<u-input placeholder="请输入查询身份证"
				 type="text"
				:customStyle="{'width':'550rpx'}" 
				:placeholderStyle="{'color':'#FFF'}" border="bottom" v-model="bindcode" @change="changeinput" fontSize="18" color="#000" maxlength="19"></u-input>
			</view>
			<view class="mt-3">
				<u-button type="primary" shape="circle" text="确认绑定" @click="cepingcheck"></u-button>
			</view>
		</view>
	</view>
</template>

<script setup lang='ts'>
import { ref,reactive } from 'vue'
import {  onLoad,onShow } from '@dcloudio/uni-app'
import { userStore } from '@/stores/userStore'
const store = userStore();
let { hasLogin,userData } = userStore();


const dcustomstyle=reactive({
	"background":"#ccc",
	"border":"0px",
});

let bindcode=ref('');


const changeinput=(e:any)=>{
	console.log("输入发生变化:",e);
	userData.binduseridcard=e;
}

onLoad((evt)=>{
	// if(evt!=null){
			
	// }
	//cepingLogin(); //执行登录
	//getH5Link();
});

onShow(()=>{

});





const cepingcheck=()=>{
	
	
	if(userData.userinfo===null || hasLogin===false){
		uni.$tools.Toast("会话已失效,请重新登录");
		setTimeout(()=>{
			uni.$tools.GoUrl('/pages/login/login?keyid=ceping',0);
		},1000);
		return;
	}
	
	if(!/\S/.test(bindcode.value)){
		uni.$tools.Toast("请输入查询身份证");
		return;
	}
	
	if(!/\S/.test(store.phone)){
		uni.$tools.Toast("会话已失效,请重新登录");
		setTimeout(()=>{
			uni.$tools.GoUrl('/pages/login/login?keyid=ceping',0);
		},1000);
		return;
	}
	
	cepingLogin(); //第三方登录并跳转
}


//测评登录（第三方调佣）
const cepingLogin=()=>{
	let paraData={
		indexNumber:1,
		userNumber:userData.userinfo.id,
		phone:store.phone,
		//phone:'153611020050' ,//测试
		idcard:bindcode.value
	}
	console.log("测评登录绑定参数:",paraData);
	uni.$tools.Reqeust('/webservices/mbLogin',paraData,'POST').then((res:any)=>{
			console.log('查询测评结果:',res);
			if (res.data.code == 200) {
				if(res.data.data!=null && res.data.data.indexOf("https")!=-1){
					//返回了http链接
					let h5link=res.data.data;
					let accessUrl="/pages/webview/webview";
					store.backRouter=h5link;
					uni.$tools.GoUrl(accessUrl);	
				}
			}else{
				uni.$tools.Toast(res.data.msg);
			}
	})
}

const getH5Link=()=>{
	let paraData={
	}
	console.log("查询绑定参数:",paraData);
	uni.$tools.Reqeust('/api/fushubindcheck',paraData,'POST').then((res:any)=>{
			console.log('查询绑定结果:',res);
			if (res.data.code == 200) {
	
			}else{
				uni.$tools.Toast(res.data.msg);
			}
	})
}
</script>
<style>
	page{
		background:#f6eade;
	}
</style>
<style lang='scss' scoped>
	@import "ceping.scss";
</style>